package org.jpass.dc.common.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AuthorityInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();
		HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		String requestPath=request.getServletPath();
		String user = (String) ctx.getSession().get("user");
		if (user != null) {
			return invocation.invoke();
		} else {
			if(requestPath.startsWith("/backstage/")){ //如果请求后台页面则转到后台登录页
				return "backlogin";
			}else{
				return Action.LOGIN;
			}
		}
	}
}
